package demo.kafka.streams.job;

import demo.kafka.streams.utils.Constants;
import demo.kafka.streams.utils.KafkaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class Tasks {

    @Value("${LANE}")
    private String appLane;


    @Value("${KAFKA_TOPIC}")
    private String laneTopic;

    @Value("${KAFKA_TOPIC2}")
    private String laneTopic2;

    private KafkaTemplate<String, String> kafkaTemplate;

    @Autowired
    public void setKafkaTemplate(KafkaTemplate<String, String> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    @PostConstruct
    public void init(){
//        KafkaUtil.startConsumer("test.stan.wordCount", true);

        KafkaUtil.startProducer("test.stan", true);

        System.err.println("泳道：" + appLane + "，topic：" + laneTopic + "，topic2：" + laneTopic2);
    }

    @Scheduled(fixedRate = 10000)
    public void printEnv() {

//        kafkaTemplate.send(Constants.KAFKA_TOPIC, "辛弃疾《破阵子・为陈同甫赋壮词以寄之》", "醉里挑灯看剑，梦回吹角连营。八百里分麾下炙，五十弦翻塞外声，沙场秋点兵。\n" +
//                "马作的卢飞快，弓如霹雳弦惊。了却君王天下事，赢得生前身后名。可怜白发生！");
    }
}
